﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using KingRoad.EPM.PersonnelLogEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.PersonnelLogDAL.PlmPersonnelAttendanceService;


namespace KingRoad.EPM.PersonnelLogBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/3/24 15:38:50
    /// </summary> 
    public class PlmPersonnelattendanceUIRule
    {
        private readonly IPlmPersonnelattendanceService _plmPersonnelattendanceService;
        
        
        public PlmPersonnelattendanceUIRule(){}
        
        /// <summary> 
        /// construct function... 
        /// </summary> 
        public PlmPersonnelattendanceUIRule(IPlmPersonnelattendanceService  plmPersonnelattendanceService)
        {
           _plmPersonnelattendanceService=plmPersonnelattendanceService;
        }
        /// <summary>
        /// 获取人员考勤信息
        /// </summary>
        /// <returns></returns>
        public List<PlmPersonnelattendanceInfo> GetAllPersonnelAttendance(string sql)
        {
            var list = _plmPersonnelattendanceService.GetEntityList(sql);
            return list;
        }
        /// <summary>
        /// 根据ID获取Info
        /// </summary>
        /// <param name="parentID">主键ID</param>
        /// <returns></returns>
        public PlmPersonnelattendanceInfo GetInfoByID(Guid ID)
        {
            var list = _plmPersonnelattendanceService.GetEntityById(ID);
            return list;
        }
        /// <summary>
        /// 根据条件查询List信息(分页)
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<PlmPersonnelattendanceInfo> GetListForPage(int numCurrentPage, int numPerPage,
                                                                        string orderByField, out int totalRecord, string sqlCondition, string desc = "asc")
        {
            var list = _plmPersonnelattendanceService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition, desc);
            return list;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool InsertEntity(PlmPersonnelattendanceInfo entity)
        {
            var ret = _plmPersonnelattendanceService.InsertEntity(entity);
            return ret > 0;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateEntity(PlmPersonnelattendanceInfo entity)
        {
            var ret = _plmPersonnelattendanceService.UpdateEntity(entity);
            return ret > 0;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteEntity(string id)
        {
            var ret = _plmPersonnelattendanceService.DeleteEntityByStringID(id);
            return ret > 0;
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool DeleteEntityByMultiStringID(string ids)
        {
            var ret = 0;
            foreach (string id in ids.Split(','))
            {
                ret = _plmPersonnelattendanceService.DeleteEntityByStringID(id);
            }
            return ret > 0;
        }
        ///<summary>
        /// 根据标段对应考勤信息
        /// </summary>
        /// <param name="section">标段</param>
        /// <returns></returns>
        public List<PlmPersonnelattendanceInfo> GetPersonnelAttendanceBySection(string section)
        {
            string sql = "";
            if (section != "")
                sql = " PA_UnitCode='" + section + "' ";
            var list = _plmPersonnelattendanceService.GetEntityList(sql);
            return list;
        }
        ///<summary>
        /// 根据标段对应考勤信息
        /// </summary>
        /// <param name="section">标段</param>
        /// <returns></returns>
        public List<PlmPersonnelattendanceInfo> GetPersonnelAttendanceBySectionAndDate(string section,string date)
        {
            string sql = "";
            if (section != "")
                sql = " PA_UnitCode='" + section + "' and Convert(varchar,PA_Date,120) like '" + date + "%' ";
            var list = _plmPersonnelattendanceService.GetEntityList(sql);
            return list;
        }
       /// <summary>
        /// 按条件删除
       /// </summary>
       /// <param name="Date">时间</param>
       /// <param name="Section">标段</param>
       /// <returns></returns>
        public bool DeleteBySql(string Date,string Section)
        {
            var ret = _plmPersonnelattendanceService.DeleteBySql("Convert(varchar,PA_Date,120) like'" + Date + "%' and  PA_UnitCode='" + Section + "'");
            return ret > 0;
        }
        public List<PlmPersonnelattendanceInfo> GetListBySql(string name, string section, string time)
        {
            var list = _plmPersonnelattendanceService.GetEntityList("replace(PA_PersonnelName,' ','')=replace('"+name+"',' ','') and PA_UnitCode='" + section + "' and  CONVERT(varchar(120), PA_Date, 120) LIKE '" + time + "%'");
            return list;
        }
    }
}

